import React, { useCallback, useEffect, useState } from 'react';
import useBasisCash from './useBasisCash';
import config from '../config';
import {useV1} from "../state/v1action/hooks";
import {useSelector} from "react-redux";
import {AppState} from "../state";
const useHusdPool = (token:string,v2:boolean):any => {
  const [stat, setStat] = useState({});
  const basisCash = useBasisCash();

  const fetchLiquidityOracle = useCallback(async () => {
      const stat = await basisCash.getHusdPoolStat(token,v2);
      setStat(stat);
  }, [basisCash,v2]);

  useEffect(() => {
    fetchLiquidityOracle().catch((err) => console.error(`Failed to fetch SNB price: useCashStats ${err.stack}`));
    const refreshInterval = setInterval(fetchLiquidityOracle, config.refreshInterval);
    return () => clearInterval(refreshInterval);
  }, [basisCash,v2]);

  return stat;
};

export default useHusdPool;
